<?php
namespace app\common\search;

/**
 * 提供搜索条件
 */
class ActivityBalance extends Base{
	protected $request = 'ActivityBalance';

	//匹配最适合的活动
	public function current($model, $balance) {
		$this->ongoing_ipl($model);
		$model->where('fee', '<=', $balance);
		$model->order('fee desc');
	}

	//匹配进行中的活动
	public function ongoing($model) {
		$this->ongoing_ipl($model);
		$model->order('fee desc');
	}

	//匹配进行中的活动实际执行
	public function ongoing_ipl($model) {
		$model->where(function($query) {
			$currentTime = time();
			$query->where(function($query) use ($currentTime) {
				$query->where('startime', '<', $currentTime)->where('endtime', '>', $currentTime);
			})->whereOr(function($query) {
				$query->where('startime', 0)->where('endtime', 0);
			});
		});
	}
}

